﻿// ***********************************************************************
// Assembly         : STX.Domain
// Author           : seven.x
// Created          : 01-03-2014
//
// Last Modified By : seven.x
// Last Modified On : 02-25-2014
// ***********************************************************************
// <copyright file="BizActivity.cs" company="驰创数码">
//     Copyright (c) 驰创数码. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;

namespace STX.Domain
{
    /// <summary>
    /// Class 活动.
    /// </summary>
    public class BizActivity : BaseEntity
    {



        /// <summary>
        /// Gets or sets the project unique identifier.
        /// </summary>
        /// <value>The project unique identifier.</value>
        public int ProjectId { get; set; }

        /// <summary>
        /// Gets or sets the administrator unique identifier.
        /// </summary>
        /// <value>The administrator unique identifier.</value>
        public int AdministratorId { get; set; }

        /// <summary>
        /// 活动名称
        /// </summary>
        /// <value>The name.</value>
        public string Name { get; set; }


        /// <summary>
        /// 活动开始时间
        /// </summary>
        /// <value>The start time.</value>
        public DateTime StartTime { get; set; }

        /// <summary>
        /// Gets or sets the time detail.
        /// </summary>
        /// <value>The time detail.</value>
        public string TimeDetail { get; set; }

        /// <summary>
        /// 活动结束时间
        /// </summary>
        /// <value>The end time.</value>
        public DateTime EndTime { get; set; }


        /// <summary>
        /// 活动地点
        /// </summary>
        /// <value>The place.</value>
        public string Place { get; set; }


        /// <summary>
        /// 负责人
        /// </summary>
        /// <value>The responsible person.</value>
        public string ResponsiblePerson { get; set; }


        /// <summary>
        /// 报价制表人
        /// </summary>
        /// <value>The quotation tabulator.</value>
        public string QuotationTabulator { get; set; }


        /// <summary>
        /// 报价制表时间
        /// </summary>
        /// <value>The quotation generated time.</value>
        public DateTime QuotationGeneratedTime { get; set; }


        /// <summary>
        /// 成本制表人
        /// </summary>
        /// <value>The cost tabulator.</value>
        public string CostTabulator { get; set; }


        /// <summary>
        /// 成本制表时间
        /// </summary>
        /// <value>The cost generated time.</value>
        public DateTime CostGeneratedTime { get; set; }


        /// <summary>
        /// 执行人
        /// </summary>
        /// <value>The executor.</value>
        public string Executor { get; set; }


        /// <summary>
        /// 策划人
        /// </summary>
        /// <value>The planner.</value>
        public string Planner { get; set; }


        /// <summary>
        /// 司机
        /// </summary>
        /// <value>The driver.</value>
        public string Driver { get; set; }


        /// <summary>
        /// 合同
        /// </summary>
        /// <value>The contract URL.</value>
        public string ContractUrl { get; set; }

        /// <summary>
        /// Gets or sets the biz project.
        /// </summary>
        /// <value>The biz project.</value>
        public virtual BizProject BizProject { get; set; }

        /// <summary>
        /// Gets or sets the administrator.
        /// </summary>
        /// <value>The administrator.</value>
        public virtual TabAdministrator Administrator { get; set; }

        /// <summary>
        /// 报价明细
        /// </summary>
        /// <value>The biz activity items.</value>
        public virtual List<BizActivityItem> BizActivityItems { get; set; }

        /// <summary>
        /// Gets or sets the auditing.
        /// </summary>
        /// <value>The auditing.</value>
        public AuditingEnum Auditing { get; set; }

        /// <summary>
        /// Gets or sets the step.
        /// </summary>
        /// <value>The step.</value>
        public StepEnum Step { get; set; }

        /// <summary>
        /// Gets or sets the comment.
        /// </summary>
        /// <value>The comment.</value>
        public string Comment { get; set; }

        /// <summary>
        /// 总报价
        /// </summary>
        /// <value>The total quotation.</value>
        [NotMapped]
        public decimal TotalQuotation
        {
            get
            {
                if (BizActivityItems == null) return 0;
                return BizActivityItems.Sum(o => o.QuotationPrice*o.Numb);
            }
        }

        /// <summary>
        /// 最终金额
        /// </summary>
        /// <value>The receivable amount.</value>
        [NotMapped]
        public decimal ReceivableAmount
        {
            get
            {
                return TotalQuotation + IncreaseOrDecrease;
            }
        }


        /// <summary>
        /// 增减情况
        /// </summary>
        /// <value>The increase original decrease.</value>
        public decimal IncreaseOrDecrease { get; set; }

        #region 发票

        /// <summary>
        /// 通知开票
        /// </summary>
        /// <value>The apply invoice man.</value>
        public string ApplyInvoiceMan { get; set; }

        /// <summary>
        /// 通知日期
        /// </summary>
        /// <value>The apply invoice date.</value>
        public DateTime ApplyInvoiceDate { get; set; }

        /// <summary>
        /// 开票日期
        /// </summary>
        /// <value>The make invoice date.</value>
        public DateTime MakeInvoiceDate { get; set; }

        /// <summary>
        /// 发票号码
        /// </summary>
        /// <value>The invoice no.</value>
        public string InvoiceNo { get; set; }

        /// <summary>
        /// Gets a value indicating whether this instance is made invoice.
        /// </summary>
        /// <value><c>true</c> if this instance is made invoice; otherwise, <c>false</c>.</value>
        [NotMapped]
        public bool IsMadeInvoice
        {
            get { return !InvoiceNo.IsNullOrEmpty();   }
        }

        #endregion

        #region 回款
        /// <summary>
        /// 回款金额
        /// </summary>
        /// <value>The returned amount.</value>
        public decimal ReturnedAmount { get; set; }

        /// <summary>
        /// 回款日期
        /// </summary>
        /// <value>The returned date.</value>
        public DateTime ReturnedDate { get; set; }

        /// <summary>
        /// 是否回款
        /// </summary>
        /// <value><c>true</c> if this instance is returned; otherwise, <c>false</c>.</value>
        [NotMapped]
        public bool IsReturned{
            get
            {
                return ReturnedAmount > 0;
            }
        }

        #endregion

        #region 统计

        /// <summary>
        /// 未收款
        /// </summary>
        /// <value>The WSK.</value>
        [NotMapped]
        public decimal WSK
        {
            get
            {
                return TotalQuotation + IncreaseOrDecrease - ReturnedAmount;
            }
        }

        /// <summary>
        /// 已开票未收款
        /// </summary>
        /// <value>The ykpwsk.</value>
        [NotMapped]
        public decimal YKPWSK
        {
            get
            {
                if (IsMadeInvoice)
                    return TotalQuotation + IncreaseOrDecrease - ReturnedAmount;
                return 0;
            }
        }

        /// <summary>
        /// 未开票
        /// </summary>
        /// <value>The WKP.</value>
        [NotMapped]
        public decimal WKP
        {

            get
            {
                if (!IsMadeInvoice)
                    return TotalQuotation + IncreaseOrDecrease - ReturnedAmount;
                return 0;
            }
        }

        /// <summary>
        /// 已收款
        /// </summary>
        /// <value>The ysk.</value>
        [NotMapped]
        public decimal YSK
        {
            get
            {
                return ReturnedAmount;
            }
        }

        #endregion

        /// <summary>
        /// Enum ActivityStatusEnum
        /// </summary>
        public enum ActivityStatusEnum
        {
            /// <summary>
            /// The 未执行活动
            /// </summary>
            未执行活动=0,
            /// <summary>
            /// The 执行活动
            /// </summary>
            执行活动
        }


    }
}
